/*
 * AlertaDao.java
 *
 * Created on 11 de Novembro de 2007, 10:46
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.sgpa.persistencia;

import br.com.sgpa.dominio.Alerta;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Leandro
 */
public class AlertaDao  extends Dao<Alerta,Long>{
    
    /** Creates a new instance of AlertaDao */
    public AlertaDao(EntityManager em,Class classe) {
        super(em,classe);
    }
    
    public List<Alerta> listarMensagem(String usuario) {
        try {
            Query q = super.gerenciadorDeEntidades.createQuery("SELECT a FROM Alerta a WHERE a.destinatario = ?1 ORDER BY a.dataEnvio DESC");
            q.setParameter(1, usuario );
            return q.getResultList();
        } catch (Exception ex)  {
            return null;
        }
    }
}
